package org.gjy.m8.io;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;

/**
 * @author gjy
 * @version 1.0
 * @since 2025-11-10 15:49:48
 */
public class FileInfo {

    private final String name;
    private final boolean isDirectory;
    private final long size;
    private final long compressedSize;
    private final long lastModifiedTime;
    private final int compressionMethod;

    public FileInfo(String name, boolean isDirectory, long size,
                    long compressedSize, long lastModifiedTime, int compressionMethod) {
        this.name = name;
        this.isDirectory = isDirectory;
        this.size = size;
        this.compressedSize = compressedSize;
        this.lastModifiedTime = lastModifiedTime;
        this.compressionMethod = compressionMethod;
    }

    public String getName() {
        return name;
    }

    public boolean isDirectory() {
        return isDirectory;
    }

    public long getSize() {
        return size;
    }

    public long getCompressedSize() {
        return compressedSize;
    }

    public long getLastModifiedTime() {
        return lastModifiedTime;
    }

    public int getCompressionMethod() {
        return compressionMethod;
    }

    public double getCompressionRatio() {
        if (size == 0) return 0.0;
        return 1.0 - (double) compressedSize / size;
    }

    public LocalDateTime getLastModifiedDateTime() {
        return LocalDateTime.ofInstant(
                Instant.ofEpochMilli(lastModifiedTime),
                ZoneId.systemDefault()
        );
    }

    public String getCompressionMethodName() {
        switch (compressionMethod) {
            case 0:
                return "无压缩";
            case 1:
                return "标准压缩";
            default:
                return "未知方法(" + compressionMethod + ")";
        }
    }

    @Override
    public String toString() {
        return String.format(
                "FileInfo{name='%s', directory=%b, size=%d, compressedSize=%d, compressionRatio=%.2f%%}",
                name, isDirectory, size, compressedSize, getCompressionRatio() * 100
        );
    }

}
